package com.company.biz.user.action;

import com.company.biz.user.service.PositionService;
import com.company.user.entity.PositionEntity;
import com.company.user.req.AddPositionReq;
import com.company.user.req.DepartmentIdReq;
import com.company.user.req.PositionListByPositionIdReq;
import com.company.user.req.UpdatePositionListByPositionIdReq;
import com.company.user.vo.GeneralResult;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

@Api(description = "职位管理")
@RestController
@RequestMapping("/position")
public class PositionController extends BaseController{

    @Resource
    private PositionService positionService;

    @ApiOperation(value = "添加职位")
    @RequestMapping(value = "/addPosition", method = RequestMethod.POST)
    public GeneralResult<String> addPosition(@RequestBody AddPositionReq req) {
        boolean b = positionService.addPosition(req);
        return b ? GeneralResult.genSuccessResult("添加成功"):GeneralResult.genErrorResult("添加失败") ;
    }

    @ApiOperation(value = "通过部门id获取职位")
    @RequestMapping(value = "/getPositionListByDepartmentId", method = RequestMethod.POST)
    public GeneralResult<List<PositionEntity>> getPositionListByDepartmentId(@RequestBody DepartmentIdReq req) {
        List<PositionEntity> positionEntities = positionService.getPositionListByDepartmentId(req.getDepartmentId());
        return  GeneralResult.genSuccessResult(positionEntities);
    }

    @ApiOperation(value = "通过职位id获取职位")
    @RequestMapping(value = "/getPositionListByPositionId", method = RequestMethod.POST)
    public GeneralResult<PositionEntity> getPositionListByPositionId(@RequestBody PositionListByPositionIdReq req) {
        PositionEntity positionEntity = positionService.getPositionListByPositionId(req.getPositionId());
        return   GeneralResult.genSuccessResult(positionEntity);
    }

    @ApiOperation(value = "通过职位id修改职位")
    @RequestMapping(value = "/updatePositionListByPositionId", method = RequestMethod.POST)
    public GeneralResult<String> updatePositionListByPositionId(@RequestBody UpdatePositionListByPositionIdReq req) {
        boolean b = positionService.updatePositionListByPositionId(req);
        return  b ? GeneralResult.genSuccessResult("修改成功"):GeneralResult.genErrorResult("修改失败");
    }
    @ApiOperation(value = "通过职位id删除职位")
    @RequestMapping(value = "/deletePositionByPositionId", method = RequestMethod.POST)
    public GeneralResult<String> deletePositionByPositionId(@RequestBody PositionListByPositionIdReq req) {
        boolean b = positionService.deletePositionByPositionId(req.getPositionId());
        return  b ? GeneralResult.genSuccessResult("删除成功"):GeneralResult.genErrorResult("删除失败");
    }



}
